<template>
  <div class="app-container">
    <div v-show="type == 0">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-form-item label="合同名称" prop="contractName">
          <el-input
            v-model="queryParams.contractName"
            placeholder="请输入合同名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input
            v-model="queryParams.projectName"
            placeholder="请输入项目名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="项目编号" prop="projectNumber">
          <el-input
            v-model="queryParams.projectNumber"
            placeholder="请输入项目编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="负责人" prop="projectLeader">
          <el-input
            v-model="queryParams.projectLeader"
            placeholder="请输入负责人"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="阶段" prop="updateId">
          <el-input
            v-model="queryParams.updateId"
            placeholder="请选择阶段"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table
        v-loading="loading"
        :data="implementationList"
        height="400"
        :row-style="{ height: '30px' }"
        border
        :cell-style="{ padding: '0px' }"
        highlight-current-row
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
          prop="index"
          :index="indexMethod"
        />
        <el-table-column
          label="合同名称"
          align="center"
          prop="contractName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="项目名称"
          align="center"
          prop="projectName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="项目编号"
          align="center"
          prop="projectNumber"
          width="100"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="负责人"
          align="center"
          prop="projectLeader"
          width="100"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="计划时间"
          align="center"
          prop="plannedStartTime"
          width="180"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <span>{{
              parseTime(scope.row.plannedStartTime, "{y}-{m}-{d}") +
              "～" +
              parseTime(scope.row.plannedEndTime, "{y}-{m}-{d}")
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="点前阶段"
          align="center"
          prop="updateId"
          width="100"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="100"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              title="编辑"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <div v-if="type == 1">
      <Operate @change="close" :implementationId="implementationId" :enterpriseId="enterpriseId"></Operate>
    </div>
  </div>
</template>

<script>
import { listImplementation } from "@/api/project/implementation";

import Operate from "./operate.vue";
import Enterprise from "../../enterprise/person/enterprise.vue";

export default {
  name: "Implementation",
  components: { Operate },
  data() {
    return {
      type: 0,
      enterpriseId: null,
      implementationId: null,
      index: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目实施表格数据
      implementationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        contractName: null,
        projectName: null,
        projectNumber: null,
        projectLeader: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询项目实施列表 */
    getList() {
      this.loading = true;
      listImplementation(this.queryParams).then(response => {
        this.implementationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    indexMethod(index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectPlanningId: null,
        creationId: null,
        creationName: null,
        creationTime: null,
        updateId: null,
        updateName: null,
        updateTime: null,
        organizationId: null,
        organizationName: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.implementationId = row.id;
      this.enterpriseId = row.enterpriseId;
      this.type = 1;
    },

    close() {
      this.$emit("change");
      this.type = 0;
      this.getList();
    },
  },
};
</script>
